package com.usefullc.system.log;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CommonsRequestLoggingFilter;

/**
 * @author: Sampson
 * @date: 2021-05-25 10:53
 */
@Configuration
public class LogConfigure {


//    User loginUser = userService.getLoginUser(request);
    @Bean
    public CommonsRequestLoggingFilter requestLoggingFilter() {
        CommonsRequestLoggingFilter loggingFilter = new ReqLogFilter();
//        loggingFilter.setIncludeHeaders(true);
        loggingFilter.setIncludeClientInfo(true);
        loggingFilter.setIncludeQueryString(true);
        loggingFilter.setIncludePayload(true);
        loggingFilter.setMaxPayloadLength(20000);

        loggingFilter.setBeforeMessagePrefix("");  // 设置 before request 日志前缀，默认为：Before request [
        loggingFilter.setBeforeMessageSuffix("");  // 设置 before request 日志后缀，默认为：]
        loggingFilter.setAfterMessagePrefix("");   // 设置 before request 日志前缀，默认为：After request [
        loggingFilter.setAfterMessageSuffix("");   // 设置 after request 日志后缀，默认为：]

        return loggingFilter;
    }

//    @Bean
//    public CommonsLoggingFilter responseLoggingFilter() {
//        CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
//        loggingFilter.setIncludeHeaders(true);
//        loggingFilter.setIncludeClientInfo(true);
//        loggingFilter.setIncludeQueryString(true);
//        loggingFilter.setIncludePayload(true);
//        loggingFilter.setMaxPayloadLength(2000);
//        return loggingFilter;
//    }
}
